<template>
  <div>
    <el-table :data="dataList" size="mini" :loading="loading">

      <el-table-column label="id" prop="id">
        <template #default="scope">
          <div>
            {{ scope.row['id'] }}
          </div>
        </template>
      </el-table-column>

      <el-table-column label="label" prop="label">
        <template #default="scope">
          <div>
            {{ scope.row['label'] }}
          </div>
        </template>
      </el-table-column>


      <el-table-column label="value" prop="value">
        <template #default="scope">
          <div>
            {{ scope.row['value'] }}
          </div>
        </template>
      </el-table-column>


      <el-table-column label="操作" fixed="right">
        <template #default="scope">
          <div>
            <el-button type="text" @click="() => triggerModify(scope.row)"
            >编辑
            </el-button
            >

            <el-button type="text" @click="() => triggerdeleteone(scope.row)"
            >删除
            </el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script setup>
import FormDialog from '../../components/FormDialog';
import { alertConfirm, alertWithPaylod } from '@/utils/alertUtils';
import axios from 'axios';
import { ref, onMounted } from 'vue';

const dataList = ref([]);
const total = ref(0);
const queryParams = ref({ pageNum: 1, pageSize: 10 });
const loading = ref(false);

async function getInfoList() {
  loading.value = true;
  var result = await axios
      .post('/api/tb_dictdetails/apis', {
        _name: 'getlist',
        module: '',
        ...queryParams.value,
      })
      .then((res) => res.data);
  total.value = result?.count || result?.total;
  dataList.value = result?.data || [];
  loading.value = false;
}

async function triggerModify(row) {
console.log("=>(dltlist.vue:75) row", row);
  var result = await FormDialog({
    title: '管理',
    data() {
      return { ...row };
    },
    components: {
      modify: () => import('@/views/tb_dictdetails/modify.vue'),
    },
  });
  console.log('result :', result);
  if (result?.success) {
    getInfoList();
  }
}

async function triggerdeleteone(row) {
  await alertConfirm('确定删除吗？');
  var result = await axios
      .post('/api/tb_dictdetails/apis', {
        _name: '删除',
        module: '',
        ...row,
      })
      .then((res) => res.data);
  alertWithPaylod(result);
  if (result?.success) {
    getInfoList();
  }
}

async function initByDialog(_data) {
  queryParams.value.dic_id = _data?.dic_id;
  getInfoList();
}

async function submitByDialog() {
  //validate
  //data operation
  //ajax 提交
  return { success: true };
}

defineExpose({
  initByDialog,
});
</script>
